﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Compiler
{
    public struct Entry
    {
        public SimpleParseTableState state;
        public Symbol symbol;

        public Entry(SimpleParseTableState state, Symbol symbol)
        {
            this.state = state;
            this.symbol = symbol;
        }

        public override string ToString()
        {
            return symbol.ToString() + " " + state.ToString();
        }
    }

    class EntryEqualityComparer : IEqualityComparer<Entry>
    {
        Symbol.SymbolEqualityComparer symbolCmp = new Symbol.SymbolEqualityComparer();
        SimpleParseTableState.SimpleParseTableStateEqualityComparer stateCmp = new SimpleParseTableState.SimpleParseTableStateEqualityComparer();

        public bool Equals(Entry x, Entry y)
        {
            return symbolCmp.Equals(x.symbol, y.symbol) && stateCmp.Equals(x.state, y.state);
            //return x.state == y.state && x.symbol.Name == y.symbol.Name;
        }

        public int GetHashCode(Entry obj)
        {
            return stateCmp.GetHashCode(obj.state) + 17 * symbolCmp.GetHashCode(obj.symbol);
            //return obj.state.GetHashCode() + 17 * obj.symbol.Name.GetHashCode();
        }
    }
}
